import { Body, Controller, Post } from '@midwayjs/core';
import { Validate } from '@midwayjs/validate';
import * as NodeJieBa from 'nodejieba';
import pinyin from 'pinyin';
import { JieBaCutValidator } from '../../validator/jieba/jieba';

@Controller('/jieba', { tagName: '结巴分词' })
export class JieBaController {
  @Post('/cut', { summary: '分词' })
  @Validate()
  async cut(@Body() body: JieBaCutValidator) {
    return await NodeJieBa.cut(body.sentence, true);
  }

  @Post('/pinyin', { summary: '拼音' })
  @Validate()
  async pinyin(@Body() body: JieBaCutValidator) {
    return pinyin(body.sentence, {
      segment: '@node-rs/jieba',
    });
  }
}
